package com.four.order.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.four.order.pojo.Order;
import com.four.order.service.OrderService;
import com.google.gson.Gson;
import com.four.order.service.impl.OrderServicelmpl;
@WebServlet("/selectorder.do")
public class SelectorderAllServiet extends HttpServlet{
		protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
			req.setCharacterEncoding("UTF-8");
			resp.setCharacterEncoding("UTF-8");
			OrderService service = new OrderServicelmpl();
			List<Order> list = service.selectAll();
			resp.setContentType("application/json");
			PrintWriter pw = resp.getWriter();
			Gson gson = new Gson();
			String result = gson.toJson(list); 
			pw.append(result);
			pw.flush();
			pw.close();
		}
		protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
			this.doGet(req, resp);
		}
	}

